package shape;

import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

public class Wedge extends Mesh {
    protected Vector3f[] vertices = new Vector3f[18];
    protected static final short[] GEOMETRY_INDICES_DATA = {
        0,  1,  2, // back
        3,  4,  6,  4,  5,  6, // right
        7,  8,  9, // front
        10, 11, 13, 11, 12, 13, // hypotenuse
        14, 15, 17, 15, 16, 17  // bottom
    };
    protected static final float[] GEOMETRY_NORMALS_DATA = {
        0,  0, -1,  0,  0, -1,  0,  0, -1, // back
        1,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0, // right
        0,  0,  1,  0,  0,  1,  0,  0,  1, // front
	-0.5f, 0.5f, 0, -0.5f, 0.5f, 0, -0.5f, 0.5f, 0, -0.5f, 0.5f, 0, // hypotenuse
        0, -1,  0,  0, -1,  0,  0, -1,  0,  0, -1,  0  // bottom
    };
    protected static final float[] GEOMETRY_TEXTURE_DATA = { //some of these these could be backward, not sure until we try a real texture
        0, 0, 1, 0, 0, 1, // back
        0, 0, 1, 0, 1, 1, 0, 1, // right
        0, 0, 1, 0, 0, 1, // front
        0, 0, 1, 0, 1, 1, 0, 1, // hypotenuse
        0, 0, 1, 0, 1, 1, 0, 1  // bottom
    };
    
    public Wedge() {
        this(1, 1, 1);
    }

    public Wedge(float xExtent, float yExtent, float zExtent) {
	initVertices(xExtent, yExtent, zExtent);
	createShape();
    }
    
    private void initVertices(float xExtent, float yExtent, float zExtent) {
        vertices[0] = new Vector3f(xExtent,-yExtent,-zExtent); vertices[1] = new Vector3f(-xExtent,-yExtent,-zExtent); vertices[2] = new Vector3f(xExtent,yExtent,-zExtent); // back
	vertices[3] = new Vector3f(xExtent,-yExtent,zExtent); vertices[4] = new Vector3f(xExtent,-yExtent,-zExtent); vertices[5] = new Vector3f(xExtent,yExtent,-zExtent); vertices[6] = new Vector3f(xExtent,yExtent,zExtent); // right
	vertices[7] = new Vector3f(-xExtent,-yExtent,zExtent); vertices[8] = new Vector3f(xExtent,-yExtent,zExtent); vertices[9] = new Vector3f(xExtent,yExtent,zExtent); // front
	vertices[10] = new Vector3f(-xExtent,-yExtent,-zExtent); vertices[11] = new Vector3f(-xExtent,-yExtent,zExtent); vertices[12] = new Vector3f(xExtent,yExtent,zExtent); vertices[13] = new Vector3f(xExtent,yExtent,-zExtent); // hypotenuse
	vertices[14] = new Vector3f(xExtent,-yExtent,-zExtent); vertices[15] = new Vector3f(xExtent,-yExtent,zExtent); vertices[16] = new Vector3f(-xExtent,-yExtent,zExtent); vertices[17] = new Vector3f(-xExtent,-yExtent,-zExtent); // bottom
    }
    
    private void createShape() {
        setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
	setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA));
	setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA));
        setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
        updateBound();
    }
}
